﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;
using BUS;


namespace CuaHangHoa
{
    public partial class Sua_mh : Form
    {
        public Sua_mh()
        {
            InitializeComponent();
        }

        public delegate void DoEvent();
        public event DoEvent RefreshDgv;


        public void Loaddata_gv(quanlymathang_DTO  mh)
        {
            txt_mahang .Text = mh.mamathang.ToString();
            txt_tenhang.Text = mh.tenhang;
            txt_xuatxu.Text = mh.xuatxu;
            txt_donvitinh .Text = mh.donvitinh;

            txt_soluongton.Text = mh.soluongton;
            txt_gianhap.Text = mh.gianhap;
            txt_tinhtrang.Text = mh.tinhtrang;
            txt_ghichu.Text = mh.ghichu;
            
        }



        private void CapNhatMH()
        {
            quanlymathang_DTO  mh = new quanlymathang_DTO ();

            mh.mamathang = int.Parse(txt_mahang.Text);
            mh.tenhang = txt_tenhang.Text;
            mh.xuatxu = txt_xuatxu.Text;
            mh.donvitinh = txt_donvitinh.Text;
            mh.soluongton = txt_soluongton.Text;
            mh.gianhap = txt_gianhap.Text;
            mh.tinhtrang= txt_tinhtrang.Text;
            mh.ghichu = txt_ghichu.Text;
            

            quanlymathang_BUS bus = new quanlymathang_BUS ();
            int kq = bus.CapNhatMatHang (mh);

            if (kq == 1)
            {
                this.RefreshDgv();
             //   this.RefreshDgv();
                MessageBox.Show("Sửa thành công");
            }
            else
            {
                MessageBox.Show("Sửa thất bại");
            }
            txt_tenhang.Focus();
        }

        

        private void Sua_mh_Load(object sender, EventArgs e)
        {

        }
        private void Load_mh()
        {
            throw new NotImplementedException();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            CapNhatMH ();
          //  errorProvider1.Clear();
           
        }

       
    }
}
